begin transaction
update conflictofinterest
set lastnotified = b.emailsentdate
from conflictofinterest coi
inner join coibatchperson cbp on cbp.admpersonid = coi.admpersonid
inner join coibatch b on b.id = cbp.coibatchid
where coi.id = (select max(id) from conflictofinterest where admpersonid = coi.admpersonid)
and cbp.addcoi = 1 and cbp.coiaddeddate is not null
commit
